package com.reger.l2cache.bloomfilter.hash;

import com.reger.l2cache.bloomfilter.Hash;

public class RotatingHash implements Hash {

	private final long cap;

	public RotatingHash(long cap) {
		super();
		this.cap = cap;
	}

	@Override
	public long hash(String key) {
		long hash;
		int i;
		for (hash = key.length(), i = 0; i < key.length(); ++i) {
			hash = (hash << 4) ^ (hash >> 28) ^ key.charAt(i);
		}
		return (hash % this.cap) & (this.cap - 1);
	}

}
